package main.java.Controller;

import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @author: Zxeao
 * @description
 * @date: 2023/4/26 23:17
 */
@WebServlet(name = "foundSearchAction", value = "/foundSearchAction")
public class foundSearchController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest requset, HttpServletResponse response) throws ServletException, IOException {
//        super.doGet(requset, response);
        this.doPost(requset, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        super.doPost(request, response);
        String Key = request.getParameter("key");
        response.setContentType("text/html;charset=UTF-8");
        response.setHeader("Content-type", "text/html;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");

        ArrayList<entity.Found> foundArrayList = new DAO.FoundDao().queryBySearch(Key);
        String allfoundArrayList = JSON.toJSONString(foundArrayList);

        entity.Return r = entity.Return.ok().data("data",allfoundArrayList);
        String returnStr = JSON.toJSONString(r);
        response.getWriter().println(returnStr);
    }
}
